<?php
/**
 * 水电气管理
 *
 * @auther 大耳牛
 * 2016-12-31
 **/
namespace Xijie\Model;
use Think\Model;
class EqmentRoomModel extends Model{
	//定义表名称
	protected $tableName = 'eqment_room';
	
	/**
	 * 获取房间列表总数
	 *
	 **/
	public function getEqmentRoomListCount($where){
		$list = $this->alias('eqmroom')
					->join('left join momoda_eqment AS eqment ON eqmroom.`eqment_id` = eqment.`id`')
					->join('left join momoda_member AS member ON eqmroom.`contract` = member.`contract`')
					->where($where)
					->count();
		//echo $this->_sql();
		return $list;			
	}
	
	/**
	 * 获取房间列表
	 *
	 **/
	public function getEqmentRoomList($page, $where){
		return $this->alias('eqmroom')
					->join('left join momoda_eqment AS eqment ON eqmroom.`eqment_id` = eqment.`id`')
					->join('left join momoda_member AS member ON eqmroom.`contract` = member.`contract`')
					->field('eqmroom.*,eqment.`last_number`,eqment.`status` AS state,eqment.updatetime,eqment.stoptime,member.`member_nick`,member.`member_phone`,member.`point`,member.contract')
					->order('eqmroom.id desc')
					->page($page, C('PAGE_SIZE'))
					->where($where)
					->select();
	}
	
	/**
	 * 房间信息保存
	 *
	 **/
	public function addEqmentRoomInfo($data){
		return $this->data($data)->add();
	}
	
	public function addEqmentInfoToRoomAll($data){
		return $this->addAll($data);
	}
	
	/**
	 * 根据合同号获取设备信息
	 ***/
	public function getEqmentInfoByContract($contract){
		return $this->where(array('contract' => $contract))->select();
	}
}